<template>
    <div>home</div>
    <div>{{ store_user.user }}</div>
    <button v-on:click="btnGet">獲取</button>
    <button v-on:click="btn">修改</button>
</template>

<script setup lang="ts">
import actions from '@/action'
import { PROJECT_KEY } from '@/config'
import { useUserStore , type User } from '@glz/utils'
import { onMounted, ref } from 'vue'

//const user = ref({} as User)

//const store = useUserStore()
//console.log(store)

//const user = ref({})

let store_user = useUserStore(PROJECT_KEY)

console.log(PROJECT_KEY,"store_user:",store_user)


const btn = ()=>{

    const userD : User = {
    token :"base-vite-ts",
    id: '12',
    account:'',
    mobile:'9999999',
    avator: ''
}

store_user.setUser(userD)


    // const globalState = {
    //     theme: "red",
    //     language: "en",
    //     useUserStore: userD
    // };

    // actions.setGlobalState(globalState)

}


const btnGet = () => {
    
     store_user = useUserStore(PROJECT_KEY)

console.log(PROJECT_KEY,"store_user:",store_user)

}


// onMounted(() => {
//     actions.onGlobalStateChange((state, prevState) => {
//     // state: 变更后的状态; prevState 变更前的状态
//     console.log(prevState, '主应用变更前')
//     console.log(state, '主应用变更后')

//     if(state.useUserStore)
//     {
//         const store_user = useUserStore()
//         store_user.user = state.useUserStore
//     }

//     },true)
// })
</script>